package com.suian.spring.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class T2Executors {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
        for (int i = 0; i < 5; i++) {
            final int taskId = i;
            System.out.println("多线程task" + taskId + " is running on thread" + Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println("多线程task" + taskId + "完成");

        }

        //关闭线程池
        executor.shutdown();
    }
}
